#!/bin/bash
version=$(date -d "8 hour" -u +%y.%m.%d.%H)
cd ~/app-root/data/github-sh/xpi/ehh
latest=$(curl -s https://addons.mozilla.org/zh-CN/firefox/addon/element-hiding-helper-for-pan/versions/ |grep '\.xpi'|awk -F '\"' '{print $2}'|sed '2,$d')
if ! grep -q "$latest" ~/app-root/data/temp/xpi/ehh/latest.txt; then
echo "$latest" > ~/app-root/data/temp/xpi/ehh/latest.txt
wget ${latest} --output-document=ehh-${version}.xpi
zip -d -r ehh-${version}.xpi META-INF/*
mv ehh-${version}.xpi do/ehh-${version}.xpi
cd do/
sed -i "s#[0-9]\{2\}\.[0-9]\{2\}\.[0-9]\{2\}\.[0-9]\{2\}#${version}#" install.rdf
zip -r ehh-${version}.xpi *
rm -f ~/app-root/runtime/repo/扩展/$(ls ~/app-root/runtime/repo/扩展/|grep "Pan2ehh-[0-9]\{2\}\.[0-9]\{2\}\.[0-9]\{2\}\.[0-9]\{2\}.xpi")
mv -f ehh-${version}.xpi ~/app-root/runtime/repo/扩展/Pan2ehh-${version}.xpi
~/app-root/data/github-sh/log/log.sh "Pan2ehh-${version}.xpi 更新"
fi
